package com.dts.evaluate.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;

import com.dts.evaluate.R;
import com.dts.evaluate.ui.view.TitleView;

import butterknife.Bind;
import butterknife.ButterKnife;

public class GoverNetActivity extends BaseActivity implements TitleView.OnBackClikListener {

    @Bind(R.id.title_view)
    TitleView titleView;
    @Bind(R.id.webview)
    WebView webview;
    @Bind(R.id.activity_gover_net)
    LinearLayout activityGoverNet;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gover_net);
        ButterKnife.bind(this);

        initView();
    }

    private void initView(){
        //设置titleview点击监听
        titleView.setOnBackClickListener(this);

        //设置webview参数
        WebSettings webSettings = webview.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setUseWideViewPort(true);//设置此属性，可任意比例缩放
        webSettings.setLoadWithOverviewMode(true);
        webSettings.setPluginState(WebSettings.PluginState.ON);
        // wv.getSettings().setPluginState(state);//可以使用插件
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        webSettings.setAllowFileAccess(true);
        webSettings.setDefaultTextEncodingName("UTF-8");
        webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
        webview.setVerticalScrollBarEnabled(false);
        webview.setVerticalScrollbarOverlay(false);
        webview.setHorizontalScrollBarEnabled(false);
        webview.setHorizontalScrollbarOverlay(false);
        webview.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
        webview.setWebChromeClient(new WebChromeClient() {

            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                super.onProgressChanged(view, newProgress);
            }
        });
        webview.loadUrl("http://www.yaan.gov.cn/htm/index.htm");
    }

    @Override
    public void onTitleViewClik(View v) {
        if(webview.canGoBack()){
            webview.goBack();
            return;
        }
        finish();
    }
}
